#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
using namespace std;

class App {
	int size;
	vector<int> icov;
	set<int> ans;
	vector<pair<int, int>> edges;
	map<int, int> rank;

	void down(int i)
	{
		if (icov[i]) {
			icov[i << 1] = icov[i];
			icov[i << 1 | 1] = icov[i];
			icov[i] = 0;
		}
	}

	void conver(int jobl, int jobr, int cov, int l, int r, int i)
	{
		if (jobl <= l && r <= jobr) {
			icov[i] = cov;
		} else {
			down(i);

			int mid = (l + r) >> 1;
			if (jobl <= mid) {
				conver(jobl, jobr, cov, l, mid, i << 1);
			}
			if (mid < jobr) {
				conver(jobl, jobr, cov, mid + 1, r, i << 1 | 1);
			}
		}
	}

	int query(int jobl, int jobr, int l, int r, int i)
	{
		if (l == r) {
			if (icov[i]) {
				ans.insert(icov[i]);
			}
		} else {
			down(i);
			int mid = (l + r) >> 1;
			if (jobl <= mid) {
				query(jobl, jobr, l, mid, i << 1);
			}
			if (mid < jobr) {
				query(jobl, jobr, mid + 1, r, i << 1 | 1);
			}
		}
		return 0;
	}

	void prepare(int n, int m)
	{
		vector<int> pos;
		for (int i = 0, l, r; i < m; i++) {
			cin >> l >> r;
			edges.push_back({ l, r });
			pos.push_back(l);
			pos.push_back(r);
		}
		pos.push_back(n);

		sort(pos.begin(), pos.end());
		pos.erase(unique(pos.begin(), pos.end()), pos.end());
		int cnt = pos.size();
		for (int i = 1; i < cnt; i++) {
			if (pos[i] - pos[i - 1] > 1) {
				pos.push_back(pos[i - 1] + 1);
			}
		}

		sort(pos.begin(), pos.end());
		size = pos.size();
		for (int i = 0; i < size; i++) {
			rank[pos[i]] = i + 1;
		}

		icov.resize(size << 2, 0);
	}

    public:
	void run()
	{
		int n, m;
		cin >> n >> m;
		prepare(n, m);

		for (int i = 0, l, r; i < m; i++) {
			l = edges[i].first;
			r = edges[i].second;
			l = rank[l];
			r = rank[r];
			conver(l, r, i + 1, 1, size, 1);
		}
		query(1, size, 1, size, 1);
		cout << ans.size() << endl;
	}

}; // namespace App

int main()
{
	App app;
	app.run();
	return 0;
}